<?php

namespace App\Models;

use App\Models\Scopes\ActiveScope;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;

    protected $fillable = [
        'account',
        'password',
        'email',
        'active',
        'ip',
        'others',
    ];

    protected $hidden = [
        'password',
        'remember_token',
    ];

    protected $casts = [
        'password' => 'hashed',
        'email_verified_at' => 'datetime',
        'others' => 'collection',
        'active' => 'bool',
    ];

    protected static function booted(): void
    {
        static::addGlobalScope(new ActiveScope('active'));
    }

    public function share(): HasOne
    {
        return $this->hasOne(Share::class);
    }
}
